package com.rd.student.ruanjian.class3.gaochenxi.LianXi1.LinkedListPrac;

import java.util.LinkedList;
import java.util.Scanner;

public class Practice {
      public static void main(String[] args) {

            LinkedList list = new LinkedList();

            Student stu1 = new Student(1, "高晨曦", "软件专业", 3, "nice", 20, 876);
            Student stu2 = new Student(2, "张思韬", "软件专业", 3, "nice", 21, 562);
            Student stu3 = new Student(3, "姜万里", "计算机专业", 1, "nice", 22, 832);
            Student stu4 = new Student(4, "郭佳宝", "计算机专业", 1, "nice", 21, 845);
            Student stu5 = new Student(5, "方周", "计算机专业", 1, "nice", 23, 972);
            Student stu6 = new Student(6, "孙昊", "计算机专业", 1, "nice", 22, 1000);

            list.add(stu1);
            list.add(stu2);
            list.add(stu3);
            list.add(stu4);
            list.add(stu5);
            list.add(stu6);

            Practice.reZongHe(list);

      }

      public static LinkedList reZongHe(LinkedList list) {
            Scanner scanner = new Scanner(System.in);
            while (true){
                  System.out.println("请输入查找类型：1.根据班级返回list  2.根据专业返回list  3.所有成员的名字汇总");
                  int type = scanner.nextInt();
                  switch (type) {
                        case 1:
                              System.out.println("请输入查找的班级：如1");
                              int type2 = scanner.nextInt();
                              if (type2 == 1) {
                                    System.out.println("以下为1班同学：");
                                    printClass(list, type2);
                                    break;
                              }

                              if (type2 == 3) {
                                    System.out.println("以下为3班同学：");
                                    printClass(list, type2);
                                    break;
                              }

                        case 2:
                              System.out.println("请输入要查找的专业：");
                              String str = scanner.next();
                              if (str.equals("计算机专业")) {
                                    System.out.println("以下为计算机专业的同学：");
                                    printMajor(list, str);
                                    break;
                              }
                              if (str.equals("软件专业")) {
                                    System.out.println("以下为软件专业的同学：");
                                    printMajor(list, str);
                                    break;
                              }
                              if (str.equals("exit")) {
                                    System.out.println("正在返回菜单栏...");
                                    return list;
                              }
                        case 3:
                              System.out.println("所有成员的名字汇总：");
                              printName(list);
                              break;
                        case 4:
                              System.out.println("计算小组成员的平均年龄：");
                              printAvg(list);
                              break;
                        case 5:
                              System.out.println("筛选年龄：");
                              System.out.println("请输入年龄段( [   ) )");
                              System.out.println("请输入一个较小的数字：");
                              int min=scanner.nextInt();
                              System.out.println("请输入一个较大的数字：");
                              int max=scanner.nextInt();
                              //在这个年龄段范围内进行筛选
                              printFilter(list,min,max);
                              break;
                        default:
                              System.out.println("输入错误");
                              break;
                  }
                  return list;
            }
      }


      private static LinkedList printFilter(LinkedList list, int min, int max) {
            System.out.println("在此年龄段的学生为:");
            for (int i = 0; i < list.size(); i++) {
                  Student stu = (Student) list.get(i);
                  if(stu.getAge()>=min&&stu.getAge()<max){
                        System.out.println(((Student) list.get(i)).getName()+"  "+((Student) list.get(i)).getAge()+"岁");
                  }
            }
            return list;
      }

//      public static int printScanner(int min){
//            Scanner scanner=new Scanner(System.in);
//            System.out.println("");
//
//      }



      private static LinkedList printAvg(LinkedList list) {
            double sum = 0.0;
            for (int i = 0; i < list.size(); i++) {
                  Student stu = (Student) list.get(i);
                  sum += stu.getAge();
            }
            System.out.println("小组的平均年龄为:"+sum/list.size());

            return list;
      }

      private static LinkedList printName(LinkedList list) {
            System.out.println("第三组所有的成员的名字：");
            for (int i = 0; i < list.size(); i++) {
                  Student stu = (Student) list.get(i);
                  System.out.println(stu.getName());
            }
            return list;
      }

      //封装打印方法
      public static LinkedList printClass(LinkedList list, int type) {
            for (int i = 0; i < list.size(); i++) {
                  Student stu = (Student) list.get(i);
                  if (stu.cla == type) {
                        System.out.println(list.get(i));
                  }
            }
            return list;
      }

      public static LinkedList printMajor(LinkedList list, String str) {
            for (int i = 0; i < list.size(); i++) {
                  Student stu = (Student) list.get(i);
                  if (stu.getMajor().equals(str)) {
                        System.out.println(list.get(i));
                  }
            }
            return list;
      }
}

class Student {
      //学号既序号
      private int num;
      //姓名
      public String name;
      //专业
      public String major;
      //班级
      public int cla;
      //评论
      public String desc;
      //年龄
      public int age;

      private int codeName;

      public Student() {

      }

      public Student(String name, String major, int cla) {
            this.name = name;
            this.major = major;
            this.cla = cla;
      }

      public Student(int num, String name, String major, int cla, String desc, int age, int codeName) {
            this.num = num;
            this.name = name;
            this.major = major;
            this.cla = cla;
            this.desc = desc;
            this.age = age;
            this.codeName = codeName;
      }

      public String getName() {
            return name;
      }

      public void setName(String name) {
            this.name = name;
      }

      public String getMajor() {
            return major;
      }

      public void setMajor(String major) {
            this.major = major;
      }

      public String getDesc() {
            return desc;
      }

      public void setDesc(String desc) {
            this.desc = desc;
      }

      public int getAge() {
            return age;
      }

      public void setAge(int age) {
            this.age = age;
      }

      public int getCla() {
            return cla;
      }

      public void setCla(int cla) {
            this.cla = cla;
      }

      public int getCodeName() {
            return codeName;
      }

      public void setCodeName(int codeName) {
            this.codeName = codeName;
      }

      public int getNum() {
            return num;
      }

      public void setNum(int num) {
            this.num = num;
      }


      @Override
      public String toString() {
            return "[" + "name='" + name + '\'' + ']';
      }
}
